home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000100_icon-group-sender_Tue Dec 9 12:35:09 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id hB9JYj008755
for icon-group-addresses; Tue, 9 Dec 2003 12:34:45 -0700 (MST)
Message-Id: <200312091934.hB9JYj008755@baskerville.CS.Arizona.EDU>
From: Steve Wampler <swampler@noao.edu>
X-Newsgroups: comp.lang.icon
Subject: Re: Desperately in need of help
Date: Tue, 09 Dec 2003 09:02:22 -0700
X-Complaints-To: abuse@noao.edu
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
To: icon-group@cs.arizona.edu
X-Spam-Status: No, hits=-3.0 required=5.0
tests=BAYES_20,QUOTED_EMAIL_TEXT,REFERENCES,USER_AGENT
version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
On Mon, 08 Dec 2003 23:10:48 -0800, Afgncaap5 wrote:
...
> Anyway, I'm working towards creating a very simple, basic program that
> will create data tables. Each cell of the table is named after a
> letter of the alphabet, and each cell contains the number of times
> that this letter has been encountered in the input. After this stage,
> a random number generator is used to find a number between 0 and 1,
> and each of the numbers in the cells are to be divided by the sum
> total of all of the cells. The program will then select a letter of
> the alphabet based on all of this.
>
> Now, my prof keeps telling me that there's an error in the code but is
> absolutely refusing to tell me where the error is, what the error is
> doing, and how I can go about fixing it. Can someone help me?
> Included is a copy of the material that I'm working with.
Have you tried compiling the code yet? There's definitely
a syntax error - there is no keyword &alphabet. I suspect
you mean &lcase again. This is a bit worrisome, as it means
you haven't tried running the program yourself yet...
There are also some logic flaws, from what I understand of
the problem. For example:
As it's written now, the entire program can be rewritten as:
procedure main()
write("z")
end
which probably isn't what you want! (My guess is that this
is a work in progress, where you'll be adding more to the
program as you get this part running.)
Finally, the statement:
&random := 0
probably isn't doing what you want. That does not
randomize a timer. In fact, 0 is the initial value
of &random, so the above line isn't really doing anything.
If you want a different sequence of random numbers generated
each time you run the program, you'll have to assign a
unique (different) seed to &random each time you run the
program.
> procedure main()
> &random :=0 #randomizes the timer
> primary := table(0) #Creates a table with all values equal to zero
>
> test := string(&lcase) # Creates a string based on all lower-case
> letters
>
> every primary[!test] +:=1 #Goes through every letter in the alphabet
> and increments it by one
> sum := 0 # creates a value of sum equal to zero
> every x := !&lcase do
> sum +:= primary[x]
>
> cumcounts := 0
> cumprob := table(0.0000)
> every x:=!&lcase do{
> cumcounts +:= primary[x]
> cumprob[x]:=(cumcounts*1.0000)/(sum *1.0000)
> }
>
>
> randnum := ?0
> every x := !&alphabet do {
> if randnum <= primary[x] then {
> letter := x
> }
> }
>
> write(x)
>
> end